﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using MediaMonitor.Common;
using System.Text;

namespace MediaMonitor
{


    public partial class DefaultMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
                //FillCountries();
                GetMadiaAndMediaTypes();
            }
        }



        public void GetMadiaAndMediaTypes()
        {
            StringBuilder strMedia = new StringBuilder();
            DataTable dtMediaType = Adex.MediaType.Query().ExecuteDataSet().Tables[0];
            strMedia.Append("<ul>");
            foreach (DataRow drdtMediaType in dtMediaType.Rows)
            {
                strMedia.Append("<li><a href='#'> " + drdtMediaType["MediaTypeName"] + " </a>");
                strMedia.Append("<ul>");
                DataTable dtMedia = Adex.Medium.Query().WHERE("MediaTypeCode", drdtMediaType["MediaTypeCode"]).ExecuteDataSet().Tables[0];
                foreach (DataRow drdtMedia in dtMedia.Rows)
                {
                    strMedia.Append("<li><a href='#'> " + drdtMedia["MediaName"] + " </a></li>");
                }
                strMedia.Append("</ul></li>");
            }
            strMedia.Append("</ul>");
            //ltrlMedia.Text = strMedia.ToString();
        }



        //private void FillCountries()
        //{
        //    DataTable dt = Adex.Country.Query().WHERE("Active", 1).ExecuteDataSet().Tables[0];
        //    this.rptCountries.DataSource = dt;
        //    this.rptCountries.DataBind();

        //}

        protected void lnkCountry_Clicked(object sender, EventArgs e)
        {
            byte countryId = Utility.ToByte(((LinkButton)(sender)).CommandArgument);
            //string countryName = Utility.ToStr(Adex.Country.Query().SetSelectList("CountryName").WHERE("CountryId", countryId).ExecuteScalar());
            //AppUser.SetCountry(countryId, countryName);
            //Response.Redirect(Request.RawUrl);

            string url2redirect = Utility.AppPath;

            if (countryId == 58)
                url2redirect = System.Configuration.ConfigurationManager.AppSettings["MM_DO_URL"].ToString();

            if (countryId == 177)
                url2redirect = System.Configuration.ConfigurationManager.AppSettings["MM_PR_URL"].ToString(); ;

            if (countryId == 218)
                url2redirect = System.Configuration.ConfigurationManager.AppSettings["MM_TT_URL"].ToString(); ;

            if (countryId == 231)
                url2redirect = System.Configuration.ConfigurationManager.AppSettings["MM_VE_URL"].ToString(); ;


            Response.Redirect(url2redirect);
        }
    }

}